package snooker.scoreboard;

import java.util.List;

import snooker.scoreboard.ball.Ball;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class BreakImageAdapter extends BaseAdapter {
	private Context mContext;
	private List<Ball> balls;
	
	public BreakImageAdapter(List<Ball> balls, Context c) {
		mContext = c;
		this.balls = balls;
	}
	
	public void setBalls(List<Ball> balls) {
		this.balls = balls;
	}
	
	public int getCount() {
		return balls.size();
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView;
		if (convertView == null) {  // if it's not recycled, initialize some attributes
			imageView = new ImageView(mContext);
			imageView.setLayoutParams(new GridView.LayoutParams(30, 30));
			imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
			//imageView.setPadding(8, 8, 8, 8);
		} else {
			imageView = (ImageView) convertView;
		}
		imageView.setImageResource(balls.get(balls.size() - 1 - position).getResourceId());
		return imageView;
	}
}
